﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using TravelLink.DAL;

namespace TravelLink.WebApp.Admin
{
    /// <summary>
    /// AdminWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    //[System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class AdminWebService : System.Web.Services.WebService
    {

        [WebMethod]
        public string AddNewCompany()
        {
            var dc = DataContextFactory.Create();
            TL_Company n = new TL_Company();
            n.Address = string.Empty;
            n.BankAccount = string.Empty;
            n.BankAccountName = string.Empty;
            n.BankAccountNo = string.Empty;
            n.BCNo = string.Empty;
            n.Brand = string.Empty;
            n.BrandingLogo = string.Empty;
            n.CompanyBrief = string.Empty;
            n.CompanyCode = Guid.NewGuid();
            n.CompanyFax = string.Empty;
            n.CompanyLogo = string.Empty;
            n.CompanyName = string.Empty;
            n.CompanyNameEN = string.Empty;
            n.CompanyScale = string.Empty;
            n.CompanyTel = string.Empty;
            n.ContactMobile = string.Empty;
            n.ContactPerson = string.Empty;
            n.ContactPosition = string.Empty;
            n.ContactTel = string.Empty;
            var biz = dc.TL_BussinessType.FirstOrDefault();
            if (biz != null)
            {
                n.BussinessId = biz.Idx;
            }
            var city = dc.TL_City.FirstOrDefault();
            if (city != null)
            {
                n.CityId = city.Idx;
            }
            var title = dc.TL_Title.FirstOrDefault();
            if (title != null)
            {
                n.ContactTitleID = title.Idx;
            }
            n.CreateDate = DateTime.Now;
            n.EBrand = string.Empty;
            n.Email = string.Empty;
            n.IECode = string.Empty;
            n.Notes = string.Empty;
            n.Password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("12345", "MD5").ToLower();
            n.PostCode = string.Empty;
            n.RegisterNo = string.Empty;
            n.TrcNo = string.Empty;
            n.UpdateTime = DateTime.Now;
            n.WebSite = string.Empty;
            dc.TL_Company.InsertOnSubmit(n);
            dc.SubmitChanges();
            return n.CompanyCode.ToString();
        }
    }
}
